import mockjs from 'mockjs';
import { chunk } from 'lodash';
import { delay } from 'roadhog-api-doc';

const { mock } = mockjs;

const MOCK = mock({
    'data|10': [
        {
            'id|+1': 86,
            avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
            recordName: '@cname',
            'role|1': ['参与者', '审核人', '执行者'],
            comment: '@cword(15, 100)',
            attachFileName: '任务执行说明书',
            recordTime: '@datetime',
            'result|1': [2, 3.2, 3.5, 3.8, 4],
            'type|1': ['重评申请', '重评结果']
        }
    ]
});

const proxy = {
    'POST /api/oa/v1/work/task/taskinfos/manRecord': (req, res) => {
        const { pageSize = 10, pageNo = 1, name } = req.body;
        let { data } = MOCK;

        /* 模拟搜索 */
        if (name !== '') {
            data = data.filter(item => item.name === name);
        }

        /* 模拟分页 */
        const chunkedData = chunk(data, pageSize);

        res.json({ code: 10000, data: { rows: chunkedData[pageNo - 1], total: 100 } });
    }
};

export default delay(proxy, 1000);
